package com.yuneec.droneservice.command;

import com.MAVLink.yuneec.msg_mav_rc_cmd_ack;
import com.yuneec.droneservice.model.Aircraft;
import com.yuneec.droneservice.request.IResponse;

/**
 * Created by gjw on 2017/3/27.
 */

public class GetAircraftInfo extends BaseCommand {

    public GetAircraftInfo() {
        super(MAV_RC_COMMAND.MAV_RC_CMD_GET_BIND_INFO);
    }

    @Override
    protected short[] body() {
        return null;
    }

    @Override
    public IResponse toResponse(msg_mav_rc_cmd_ack ack) {
        int code = ack.code;
        IResponse<Aircraft> response = new IResponse(ids(), code);
        if (code == MAV_RC_ERROR_CODE.MAV_RC_ERR_SUCCESS) {
            try {
                Aircraft aircraft = new Aircraft();
                aircraft.setId(uIntArrayToInt(ack.params, 0));
                response.setParam(aircraft);
            } catch (Exception e) {
                response.setCode(MAV_RC_ERROR_CODE.MAV_RC_ERR_UNKNOW);
            }
        }
        return response;
    }


}
